package com.hardydou.system.controller;

import com.hardydou.common.result.Result;
import com.hardydou.common.result.ResultHelper;
import com.hardydou.framework.log.anno.LogMetaInfo;
import com.hardydou.framework.websocket.IWsService;
import com.hardydou.framework.websocket.WsMessage;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;

/**
 * @author ：hardy
 * @description：
 * @date ：Created in 2020/7/2
 * @Copyright ：Hardydou.com
 */
@Controller
@RequestMapping("/system/ws")
@Api(tags = "WS管理")
@LogMetaInfo(module = "WS管理")
public class WsController {

    @Autowired
    IWsService wsService;

    @ApiIgnore
    @GetMapping("")
    public String index() {
        return "ws/index";
    }

    @PostMapping("/push")
    public Result push(WsMessage message) {
        message.setTime(new Date());
        wsService.send(message);
        return ResultHelper.ok();
    }
}
